<?php
// Load the QCubed Development Framework
require('../qcubed.inc.php');


require(__FORMBASE_CLASSES__ . '/OrgListFormBase.class.php');

class OrgListForm extends OrgListFormBase {
    protected $dtgOrg;
    protected $authSys;
    protected $Counter=0;
    // Override Form Event Handlers as Needed
    protected function Form_Run() {
        $this->authSys = new Perm();
        $this->authSys->IsAuthenticated(true);
    }

//		protected function Form_Load() {}

    protected function Form_Create() {
        $this->dtgOrg = new OrgDataGrid($this);
        $this->dtgOrg->SetDataBinder("dtg_Bind");
        $this->dtgOrg->CssClass = 'datagrid';
        $this->dtgOrg->AlternateRowStyle->CssClass = 'alternate';

        $this->dtgOrg->Paginator = new QPaginator($this->dtgOrg);
        $this->dtgOrg->ItemsPerPage = 20;

        $this->dtgOrg->MetaAddColumn('Name');
        $this->dtgOrg->MetaAddTypeColumn('TypeId', 'OrgType');
        $this->dtgOrg->MetaAddColumn('OracleLink');

        $this->dtgOrg->AddRowAction(new QMouseOverEvent(), new QCssClassAction('selectedStyle'));
        $this->dtgOrg->AddRowAction(new QMouseOutEvent(), new QCssClassAction());

        $this->dtgOrg->RowActionParameterHtml = '<?= QS_ENCODE($_ITEM->Id) ?>';
        $this->dtgOrg->AddRowAction(new QClickEvent(), new QAjaxAction('dtgOrgRow_Click'));
    }


    protected function dtg_Bind() {

        /*@PERM*/
        if ( $_SESSION[_SV_PERM_][_SV_PERM_Admin_Role_]== true ) {
            $this->dtgOrg->TotalItemCount = ORG::QueryCount($this->dtgOrg->Conditions);
            $this->dtgOrg->DataSource = ORG::QueryArray($this->dtgOrg->Conditions,
                    QQ::Clause(
                    $this->dtgOrg->OrderByClause,
                    $this->dtgOrg->LimitClause
            ));
        }
        else {
            $PRole = $_SESSION[_SV_PERM_][_SV_PERM_PRole_];
            $this->dtgOrg->TotalItemCount = Org::CountMyOrgAllPermCondition($this->dtgOrg->Conditions);
            $this->dtgOrg->DataSource = Org::LoadArrayMyOrgAllPermCondition($this->dtgOrg->Conditions,
                    QQ::Clause(
                    $this->dtgOrg->OrderByClause,
                    $this->dtgOrg->LimitClause
            ));
        }
    }

    protected function dtgOrgRow_Click($strFormId, $strControlId, $strParameter) {
        $intId = $strParameter;
        $strEditPageUrl = __ORG__. '/organization_edit.php/'. $intId;

        QApplication::Redirect($strEditPageUrl);

    }


}

OrgListForm::Run('OrgListForm',"tpl/organization_list.tpl.php");
?>